import org.kwis.msp.lcdui.*;
import org.kwis.msp.lwc.*;

public class Block implements GameConstants 
{
	private Image BlockRed, BlockGreen, BlockBlue, BlockYellow, BlockGrey;
	private int stageNo;
	private int stage[][] = null;

	public Block(int No)
	{
		try
		{
			BlockRed = Image.createImage("block_red.png");
			BlockGreen = Image.createImage("block_green.png");
			BlockBlue = Image.createImage("block_blue.png");
			BlockYellow = Image.createImage("block_yellow.png");
			BlockGrey = Image.createImage("block_grey.png");
		}
		catch (Exception e)
		{
			e.printStackTrace();
		}

		stageNo = No;
		stage = Stages.getStages(stageNo);
	}

	public int getStageNo()
	{
		return stageNo;
	}

	// 화면에 블록들을 그려준다.
	// Stage클래스로 부터 받은 배열을 사용하여
	// 화면에 블록들을 그려준다.
	public void paint(Graphics g)
	{
		int x=0, y=0;

		for (int i=0 ; i < BLOCK_ROW; i++)
		{
			for (int j=0 ; j < BLOCK_COLUMN ; j++ )
			{
				switch(stage[i][j]) 
				{
					case 1 : // 녹색
						g.drawImage(BlockGreen,x,y,Graphics.TOP); break;
					case 2 : // 노랑색
						g.drawImage(BlockYellow,x,y,Graphics.TOP); break;
					case 3 : // 파랑색
						g.drawImage(BlockBlue,x,y,Graphics.TOP); break;
					case 4 : // 빨강색
						g.drawImage(BlockRed,x,y,Graphics.TOP); break;
					case 5 : // 회색
						g.drawImage(BlockGrey,x,y,Graphics.TOP); break;
					default :
						break;
				}
				x += BLOCK_WIDTH;
			}
			x = 0;
			y += BLOCK_HEIGHT;
		}
	}
};